home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / vol_inf.exe / FVOLAB.ASM < prev    next >
Assembly Source File  |  1993-05-02  |  28KB  |  757 lines

  1. ; created 02/13/92
  2. ; updated 12/21/92
  3. ;   revised 04/21/93 GETVOL$ 
  4. ;       to display Norton Utilities Safe Format volume labels.
  5. ;       NU routine ends a volume label with nulls rather than spaces.
  6. ;   revised 04/22/93 SETVOL
  7. ;    Test if drive is a network drive and quit if it is.
  8. ;   revised 04/27/93 added DOS Ver 3.xx+ version information so could
  9. ;    tell source of error.  FCB functions return AX = 0FFh if drive
  10. ;    is invalid and do not set any critical error.  Only way to tell
  11. ;    if access error or if drive is invalid is to use DOS Ver 3.xx+
  12. ;    Function 59h.
  13. ;   revised 04/30/93 SETVOL
  14. ;       to handle Norton Utilities Safe Format.
  15. ;       NU routine ends a volume label with nulls rather than spaces.
  16. ;       Only function that will delete such a name is FCB function
  17. ;       13h.  However, that function is not safe to use
  18. ;       in DOS Version 2.xx.  DOS Version 2.xx marked deleted volume
  19. ;       label with 00h rather than correct 0E5h which prevented access
  20. ;       to rest of directory list.  Function 13h in MS DOS Version 5.00,
  21. ;    3.30, and COMPAQ DOS version 3.00 does not have this problem.
  22. ;    Also add check of input string for invalid characters
  23.  
  24. ;=======================================================================
  25. ;   Modifications Copyright (C) Copr. 1992, 1993 by Sidney J. Kelly
  26. ;           All Rights Reserved.
  27. ;           Sidney J. Kelly
  28. ;           150 Woodhaven Drive
  29. ;           Pittsburgh, PA 15228
  30. ;           home phone 412-561-0950 (7pm to 9:30pm EST)
  31. ;=======================================================================
  32. ; «RM82»«TS8,16,24,32,40,48»
  33.  
  34. DOSSEG
  35. .MODEL MEDIUM
  36.  
  37. EXTRN B$ASSN:FAR     ;This allows QBASIC to manipulate fixed length string
  38. EXTRN B$STDL:FAR     ;This creates null strings
  39.  
  40. .DATA
  41.     EXTRN  B$STRINGLEN:WORD      ;inside FDATA
  42.     EXTRN  B$STRINGOFF:WORD      ;inside FDATA
  43.     EXTRN  B$TEMPDATA:WORD       ;inside FDATA
  44.     ; this works inside QB as well as in run time version
  45.     EXTRN   __osversion  :word;this holds minor version in highbyte,
  46.                  ;major version in lowbyte
  47. .CODE
  48.  
  49.     Public GETVOL, SETVOL
  50. ; Please do not remove
  51. Copyright       DB    13,10,'Copyright Copr. (C) 1992, 1993 Sidney J. Kelly',13,10
  52. Copyright1      DB    'All Rights Reserved',13,10,26
  53.  
  54. EVEN        ;save space in DGROUP
  55. Old_CE          Label   DWORD
  56.   CE_Off        DW      0       ; to save space in DGROUP
  57.   CE_Seg        DW      0       ; address of previous handler
  58. Old_DTA         Label   DWORD
  59.   DTA_Off       DW      0       ; to save space in DGROUP
  60.   DTA_Seg       DW      0       ; address of previous handler
  61. Last_Error      DW      0       ; store critical error code
  62.  
  63. ; Format of an extended FCB---------------
  64. XFCB    DB      0FFh            ; signal XFCB
  65.     DB      5 Dup(0)        ; reserved DOS stuff
  66.     DB      8               ; volume attribute
  67. Drive   DB      0               ; drive code goes here
  68. FLabel  DB      11 Dup(0)       ; Volume name
  69. FExtra  DB       5 Dup(0)       ; reserved DOS stuff
  70. FNew    DB    11 Dup(0)    ; holding area for renaming
  71. FScrap  DB      15 Dup(0)       ; extra stuff and padding (6) extra
  72. ; Duncan, "Advanced MS DOS Programming" (Microsoft 1988), p366
  73. ; "Microsoft MS-DOS Programmer's Reference Guide" (Microsoft 1991)
  74.  
  75. ;=======================================================================
  76. ; DECLARE FUNCTION GETVOL$(Drive$, DosErr%)
  77. ; T$ = GETVOL$(Drive$, DosErr%)
  78. ; Purpose:
  79. ;     Returns current volume label of Drive$
  80. ; Input:
  81. ;    Drive$ = Drive letter between 'A' to 'Z'.  If out-of-range then
  82. ;        default drive is substituted
  83. ; Output:
  84. ;    T$ = the volume label.  Note that volume labels can contain spaces.
  85. ;    If any error encountered, returns NULL string
  86. ;       DosErr:
  87. ;        0 if no critical error
  88. ;           -1 if FCB error in DOS version 2.xx
  89. ;           -2 if DOS Version 4.xx w/o SHARE
  90. ;     Else
  91. ;    Standard DOS errors from function 59h
  92. ;            18 = Drive has no label
  93. ;        21 = Drive not ready
  94. ; Theory:
  95. ;    FCB's are used because they work under DOS version 2.x and they
  96. ;    report the name without putting a period between the first
  97. ;       8 letters and the last 3 or squeezing out all the spaces.
  98. ;
  99. ; Note:
  100. ;       Under DOS Ver 4.00, if SHARE is not loaded, then will return with
  101. ; a null string to prevent corruption of a large partition by reason of
  102. ; the use of FCBs.  
  103. ;
  104. ; If drive is not valid, returns a null string and an error code.
  105. ;
  106. ; Has own critical error handler.
  107. ;=======================================================================
  108.  
  109. DrvStrg EQU [BP+8]      ; mnemonic for programmer
  110. DosErr    EQU [BP+6]
  111.  
  112. EVEN
  113. GETVOL PROC FAR
  114.     Push    BP
  115.     Mov     BP,SP           ; get access to stack via BP
  116.     Push    SI        ; save index registers
  117.     Push    DI        ; ditto
  118. ;       Mov     AH,30h          ; do a DOS version check
  119. ;       Int     21h
  120.     Mov     AX,__osversion  ; faster than above
  121.     Cmp     AL,4            ; DOS version 4.xx
  122.     Jne     @f              ; not version 4.xx so skip ahead
  123.     Mov     AX,1000h        ; else,  (AL must = 0)
  124.     Int     2Fh             ; see if SHARE installed
  125.     Cmp     AL,0FFh         ; if AL = FFh then it is installed
  126.     Je      @f              ; o.k. to continue
  127.     Mov     CS:[Last_Error],-2   ; report DOS Ver 4.0x w/o SHARE
  128.     Jmp     Short Error     ; else, return null string, error
  129. @@:
  130. ;Install CE Handler, trashes  AX,BX,ES,DX, returns AX = @data
  131.     Call    CE_INSTALL
  132.     Mov     BX,DrvStrg      ; get DRIVE$
  133.     Mov     CX,[BX]         ; get length in CX
  134.     JCXZ    Use_Default     ; if LEN(Drive$) = 0 use default drive
  135.     Mov     BX,[BX+2]       ; get offset of string
  136.     Mov     AL,[BX]         ; get character in AL
  137.     And     AL,0DFh         ; capitalize character
  138.     Sub     AL,'@'          ; make it 1 biased
  139.     Or      AL,AL           ; is it 0?
  140.     Jz      Begin           ; yes, so use default drive
  141.     Cmp     AL,27           ; is it > 26?
  142.     JB      Begin           ; no, so test it
  143. Use_Default:
  144.     Mov    AH,19h        ; else read default drive
  145.     Int    21h        ; into AL (useful for testing)
  146. Begin:
  147.     ; AL must contain desired drive
  148.     Call    Search_4_Name    ; search for current volume name
  149.     ; must preserve DI because will use it below
  150.     Assume  DS:NOTHING, ES:NOTHING  ; tell MASM
  151.     Cmp     AL,0FFh         ; name found?
  152.     Jne     @f              ; yes, so check for CE errors
  153.     Call    GetErrInfo      ; else find out why not found
  154. @@:
  155.     Cmp     CS:[Last_Error],0    ; did DOS give us an error?
  156.     Jne     Error           ; got an error
  157. ; new version
  158. ;    revised 04/21/93 to handle Norton Utilities Safe Format
  159. ;    NU routine ends a volume label with nulls rather than spaces.  While
  160. ;     QBASIC PRINT function can display nul strings, other routines
  161. ;    may trigger errors.
  162.     Mov     CX,11           ; else, search for trailing spaces
  163.     Dec    DI              ; remove 1 char overrun from DI
  164.     Mov    BL,20h        ; look for a space
  165. Search_4_End:
  166.     Mov    AL,ES:[DI]    ; get character
  167.     Cmp    AL,BL        ; is it a space?
  168.     Je    @f        ; yes, jump ahead
  169.     Or    AL,AL        ; is it a nul?
  170.     Jne    Loop_Exit    ; no, have end of label
  171. @@:
  172.     Dec    DI        ; reduce pointer by 1
  173.     Loop    Search_4_End    ; loop CX times
  174. Loop_Exit:
  175.     JCXZ    Error           ; all spaces/nuls if CX = 0
  176. ; copy our string to DGROUP buffer
  177.     Mov     DX,CX           ; save length in DX temporarily
  178.     Mov     SI,OFFSET FLabel ; put source string in DS:SI
  179.     Mov     AX,SS
  180.     Mov     ES,AX
  181. ;       Assume  ES:@data
  182.     Assume  DS:@data        ; lie for a moment
  183.     Mov     DI,OFFSET B$TEMPDATA  ; put destination in ES:DI
  184.     Assume  DS:NOTHING      ; tell the truth again
  185.     Rep     MovsB           ; store all the bytes
  186.     Mov     CX,DX           ; restore CX to original length
  187. CopyString:
  188.   ; Reset CE Handler, trashes AX,DX, returns AX = @data
  189.   ; Note: must preserve CX!
  190.     Call    Clean_Up        ; restore CE and DTA info
  191.     Assume  DS:@data
  192. ; return string to BASIC
  193.     Push    DS              ; Store the Data Segment
  194.     Mov     AX,OFFSET B$TEMPDATA
  195.     Push    AX              ; Store offset of string
  196.     Push    CX              ; Store LEN of string
  197.     Push    DS              ; Store the Data Segment
  198.     Mov     AX,OFFSET B$STRINGLEN
  199.     Push    AX              ; Store Descriptor of string
  200.     Xor     AX,AX           ; tell Basic it is a variable strin